#!/usr/bin/env python3
"""linkall.py - link specified JSON common files"""

import os
import json
from os.path import join

fr = json.load(open("frwiki.json"))
def ej(articlename):
    return join("enwiki", articlename + ".txt")
    
def fj(articlename):
    return join("frwiki", articlename + ".txt")

for i, article in enumerate(fr["articles"]):
    frenchloc = fj(article["title"])
    engloc = ej(article["translation"])
    if os.access(frenchloc, os.R_OK) and os.access(engloc, os.R_OK):
        os.symlink("../" + frenchloc, join("linkedarticles", {0:06}.format(i) + ".fr"))
        os.symlink("../" + engloc, join("linkedarticles", {0:06}.format(i) + ".en"))
